package core.controller;

import core.pojo.Customer;
import core.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;

/**
 *  Controller
 */

@Controller
public class CustomerController {

    @Autowired
    private CustomerService customerService;


    @RequestMapping("findById/{cid}")
    @ResponseBody
    public Customer findById(@PathVariable String cid) {
        Customer customer = customerService.findById(cid);
        return customer;
    }

//    @ResponseBody
//    @RequestMapping("json")
//    public Customer json(Customer customer) {
//
//        customer.setCust_name("小白");
//        customer.setCust_pwd("123321");
//        customer.setCust_phone("12345678910");
//        // customer.setCust_address("北京");
//        //customer.setCid(1);
//        return customer;
//
//    }

//    @RequestMapping("showjson")
//    public String showJson(Customer customer, HttpServletRequest request) {
//        List<Customer> list = customerService.findCustomer();
//        request.setAttribute("list", list);
//        return "index";
//    }

//    @RequestMapping("deleteById")
//    public String deleteByID(Integer cid) {
//
//        customerService.deleteById(cid);
//        return "redirect:list";
//    }

//    @RequestMapping("editById")
//    public String getUser(int cid, HttpServletRequest request, Model model) {
//        request.setAttribute("customer", customerService.findById(cid));
//        model.addAttribute("customer", customerService.findById(cid));
//        return "editUser";
//    }


//    @RequestMapping("toAddCustomer")
//    public String toAddCustomer() {
//        return "addCustomer";
//    }

//    @RequestMapping("addCustomer")
//    public String addCustomer(Customer customer) {
//        customerService.save(customer);
//        return "redirect:showjson";
//    }



//    @RequestMapping("findById")
//    @ResponseBody
//    public List<Customer> findById() {
//        List<Customer> list = customerService.findAll();
//        return list;
//    }


}
